cmake_minimum_required(VERSION 3.10)
project(dmcomm LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_definitions(-DDMCOMM_LIBRARY)

include(../common/config.cmake)
include(../common/hidapi.cmake)
include(../common/cserialport.cmake)

link_directories(${PROJECT_LIBDIR})

set(SOURCES
    dmcomm.cpp
    hiddevice.cpp
    networkdevice.cpp
    serialdevice.cpp
    vd.cpp
    virtualdevice.cpp
)

set(HEADERS
    deviceinterface.h
    dmcomm.h
    hiddevice.h
    networkdevice.h
    serialdevice.h
    vd.h
    virtualdevice.h
)

add_library(${PROJECT_NAME} SHARED
    ${SOURCES}
    ${HEADERS}
)

target_link_libraries(${PROJECT_NAME} PRIVATE cserialport)

if(UNIX)
    target_link_libraries(${PROJECT_NAME} PRIVATE hidapi-hidraw)
endif()

if(WIN32)
    target_link_libraries(${PROJECT_NAME} PRIVATE hidapi)
endif()

set_target_properties(${PROJECT_NAME} PROPERTIES
    ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_LIBDIR}
    LIBRARY_OUTPUT_DIRECTORY ${PROJECT_LIBDIR}
    RUNTIME_OUTPUT_DIRECTORY ${PROJECT_LIBDIR}
)

if(UNIX)
    install(TARGETS ${PROJECT_NAME}
        LIBRARY DESTINATION /usr/local/lib/
    )
endif()
